<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page language="java" %>

<%@ page import = "org.apache.struts.util.RequestUtils" %>
<%@ page import = "org.apache.commons.beanutils.DynaBean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>


<script language="JavaScript">
<!--

<%

  // This variable isn't used; why is it here? -Craig
  /* TODO remove
  String relativeDir = "/" + csMessageListEditForm.getServiceName() 
                           + "/microsite/"
                           + csMessageListEditForm.getMicrositeId() 
                           + "/bv_dgattachments/" 
                           + csMessageListEditForm.getDiscussionId();
  */

  String nextAction = "/cs/discPageAttachmentAdd.do";
  // replace with <html:rewrite>
  String nextPage = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           nextAction,
                                           null,
                                           null,
                                           false);

%>

function openwin(file) {
  window.open(escape(file), "NewWindow", 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=450,height=338');
}

function onFileInputFocus()
{
  return document.csMessageListEditForm.newFile.focus();
}

function onClickDeleteAttachment(index, id) {
  if (confirm("<bean:message key="cs.confirm.delete.attachment"/>")) {
    document.csMessageListEditForm.action = '<html:rewrite page="/cs/discPageAttachmentRemove.do"/>';
    document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
    document.csMessageListEditForm.deleteAttIndex.value = index;
    document.csMessageListEditForm.deleteAttId.value = id;
    document.csMessageListEditForm.submit();
  }
}

function onClickReset() {
  document.csMessageListEditForm.reset();
}

function onClickPost(theForm) {
  if (validateForm(theForm)) {
    theForm.action = '<html:rewrite page="/cs/messageSave.do"/>';
    theForm.submit();
  }
  return false;
}
<%-- No related items for now 
function removeRelatedItem(OID, contentType) {
  document.csMessageListEditForm.action = '<html:rewrite page="/cs/discPageRelatedItemRemove.do"/>';
  document.csMessageListEditForm.removeRelatedId.value = OID;
  document.csMessageListEditForm.removeRelatedContentType.value = contentType;
  document.csMessageListEditForm.parentContentType.value = '25'; // Message
  document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
  document.csMessageListEditForm.method = "post";
  document.csMessageListEditForm.submit();
}

function onClickBrowseRelatable() {
  if(document.csMessageListEditForm.selectedRelatableType.value < 0) return;
  var redirectUrl;
  switch(document.csMessageListEditForm.selectedRelatableType.value) {
  // Messages
  case "25":
    redirectUrl = '<html:rewrite page="/cs/relatedMessage.do" name="csMessageListEditForm" property="urlParams" paramId="contentName" paramName="csMessageListEditForm" paramProperty="discussionName"/>';
    break;
  // documents
  case "322":
    redirectUrl = '<html:rewrite page="/cs/relatedDocument.do" name="csMessageListEditForm" property="urlParams" paramId="contentName" paramName="csMessageListEditForm" paramProperty="discussionName"/>';
    break;
  default:
    redirectUrl = '<html:rewrite page="/cs/categoryBrowse.do" name="csMessageListEditForm" property="urlParams" paramId="contentName" paramName="csMessageListEditForm" paramProperty="discussionName" />';
    if(redirectUrl.indexOf("?") > 0) {
      redirectUrl += '&amp;contentTypeId=' + document.csMessageListEditForm.selectedRelatableType.value;
    }
    else {
      redirectUrl += '?contentTypeId=' + document.csMessageListEditForm.selectedRelatableType.value;
    }

  }
  // The following two lines are necessary for netscape to correctly send the
  // query string
  var re = new RegExp('&amp;','gi');
  var newRedirectUrl = redirectUrl.replace(re,"&");

  var win = window.open(newRedirectUrl,'addRelatedItem', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=700,height=500');
  win.focus();
}

// Load the related items chosen in the pop-up window
function loadRelatedItems(OIDs, contentType) {
  document.csMessageListEditForm.relatedItems.value = OIDs;
  document.csMessageListEditForm.relatedItemsContentType.value = contentType;
  document.csMessageListEditForm.action = '<html:rewrite page="/cs/discPageAddRelated.do"/>'
  document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
  document.csMessageListEditForm.method = "post";
  document.csMessageListEditForm.submit();
}
--%>

function confirmDeleteDiscussionGroup()
{
   if (confirm('<bean:message key="cs.confirm.delete.discussion"/>'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

function confirmDeleteMessage()
{
   if (confirm('<bean:message key="cs.confirm.delete.message"/>'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

//
// Trims leading blanks.
//
function stringLeftTrim(s)
{
   return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s)
{
   return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s)
{
   return stringRightTrim(stringLeftTrim(s));
}

//
// Validate the user's entries.
//
function validateForm(theForm) 
{
   var email = stringTrim(theForm.email.value);

   if (email == "") 
   {
      alert('<bean:message key="cs.error.message.email"/>');
      return false;
   }

   var title = stringTrim(theForm.title.value);

   if (title == "") 
   {
      alert('<bean:message key="cs.error.message.title"/>');
      return false;
   }

   theForm.email.value = email;
   theForm.title.value = title;

   var attachName = stringTrim(theForm.attName.value);
   var attachFile = stringTrim(theForm.attOriginalFileName.value);

   if (attachName != "" || attachFile != "")
   {
     alert('<bean:message key="cs.error.attachment.add.more"/>');
     return false;
   }
   
   return true;
}

// -->
</script>

<!-- Zone 5 starts here.  -->
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
    <div class="pageTitle">
      <jsp:include page="/cs/microsite/micrositeNaviInfo.jsp" flush="true"/>
    </div> 
    <!--end microsite logo and name here-->

    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:define id="discussionName" name="discussionGroupDTO" property="name"/>      
       <bean:message key="cs.discussion.view" arg0="<%=discussionName.toString()%>"/>
      </span>
      <span class="right">
        <!-- Admin can always create discussion message and delete discussion  -->
        <!-- group. Participant can create discussion message if the microsite -->
        <!-- is not closed. Therefore, we only check isReadOnly for the        -->
        <!-- "Create Message" button.                                          -->
        <logic:notEqual name="isMSReadOnly" scope="request" value="true">
          <input type="button" value="<bean:message key="cs.message.create"/>" onclick="location='#create'" class="globalButton"/>
        </logic:notEqual>
        <logic:equal name="isMSOwner" scope="request" value="true">
          <input type="button" onclick="if(confirmDeleteDiscussionGroup()) location='<html:rewrite page="/cs/discussionDelete.do" name="discussionGroupDTO" property="urlParams"/>';" class="globalButton" value="<bean:message key="cs.discussion.delete"/>"/>
        </logic:equal>
      </span>
    </div> 
    <!--end title bar here-->      

<div class="blockWrap">

<!--start bottom of message list, discussion index buttons area here-->
<a name="#top"></a>

<div class="globalButtonWrap">
  <input type="button" class="globalButton" value="<bean:message key="cs.message.bottom"/>" onclick="location='#bottom'"/>
  <input type="button" class="globalButton" value="<bean:message key="cs.discussions.index"/>" onclick="location='<html:rewrite page="/cs/discussionList.do" name="micrositeNaviInfoView" property="urlParams"/>'"/>
</div>
     
<!--end bottom of message list, discussion index buttons area here-->

<!--start main content area here { list of messages } -->
<!-- Start List here -->
<table class="dataTable" border="0" cellspacing="1" cellpadding="2" 
        summary="message list table" width="100%">
  <tr class="listHeader"> 
    <th id="subject" align="left"><bean:message key="cs.message.subject"/></th>
    <th id="reply" align="left"><bean:message key="cs.message.replies"/></th>
    <th id="lastreply" align="left" nowrap><bean:message key="cs.message.last.reply"/></th>
    <!--If user is not owner, do not show "actions" word-->
    <logic:equal name="isMSOwner" scope="request" value="true">
      <th id="Actions" align="left"><bean:message key="cs.actions"/></th>
    </logic:equal>
    <logic:notEqual name="isMSOwner" scope="request" value="true">
      <th id="isOwner" align="left">&nbsp;</th>
    </logic:notEqual> 
  </tr>
<%--  <tr class="listOdd"> 
    <td headers="name"><a href="#">Meeting name</a></td>
    <td headers="DateTime"> March 16, 2003 </td>
--%>
<logic:equal name="isMSOwner" scope="request" value="true">
<logic:iterate id="message" name="discussionGroupDTO" property="messages" 
               indexId="index">

<%
Long depthLevelL = (Long) ((DynaBean) message).get("depthLevel");
long i = depthLevelL.longValue() * 12;
%>


    <tr class=<%= index.intValue() % 2 == 0 ? "\"listEven\"" : "\"listOdd\""%>>
      <td height="24" headers="subject"><html:img page="/cs/images/buttons/global/gbtn_message.gif" width="22" height="18" border="0" align="absmiddle" alt="Message icon" title="Message icon"/><html:link page="/cs/messageView.do?displayMsg=true" name="message" property="urlParams"><b><bean:write name="message" property="title" /></b></html:link></td>
      <td nowrap width="10%" headers="reply"><bean:write name="message" property="numOfMessages"/></td>
      <td nowrap width="34%" headers="lastreply"><bean:write name="message" property="lastModTime" filter="false" formatKey="format.datetime.long"/></td>
      <td nowrap align="left" width="21%" headers="Actions">
        <logic:equal name="message" property="status" value="1"> 
        <html:link page="/cs/messageStatusChange.do" name="message" property="urlParams"><html:img page="/cs/images/action/icon_deactivate.gif" styleClass="actionIcon" altKey="cs.action.deactivate" border="0"/></html:link>
        </logic:equal>
        <logic:equal name="message" property="status" value="0">   
        <html:link page="/cs/messageStatusChange.do" name="message" property="urlParams"><html:img page="/cs/images/action/icon_activate.gif" styleClass="actionIcon" altKey="cs.action.activate" border="0"/></html:link>
        </logic:equal>
          <html:link page="/cs/messageDelete.do" name="message" property="urlParams" onclick="return confirmDeleteMessage()"><html:img page="/cs/images/action/icon_delete.gif" styleClass="actionIcon" altKey="cs.action.delete" border="0"/></html:link>
      </td>
    </tr>
</logic:iterate>
</logic:equal>

<logic:equal name="isMSOwner" scope="request" value="false">
<logic:iterate id="message" name="discussionGroupDTO" property="messages"
               indexId="index">

    <tr class=<%= index.intValue() % 2 == 0 ? "\"listEven\"" : "\"listOdd\""%>>
      <td height="24" class="listItem"><html:link page="/cs/messageView.do?displayMsg=true" name="message" property="urlParams"><html:img page="/cs/images/buttons/global/gbtn_message.gif" width="22" height="18" border="0" align="absmiddle" alt=""/><b><bean:write name="message" property="title" /></b></html:link></td>
      <td nowrap width="10%" class="listItem"><bean:write name="message" property="numOfMessages"/>
      <td nowrap width="34%" class="listItem"><bean:write name="message" property="lastModTime" formatKey="format.datetime.long"/>
</td>
      <td valign="top" width="21%" >&nbsp;</td>
    </tr>

</logic:iterate>
</logic:equal>

      <logic:equal name="discussionGroupDTO" property="messages.empty" value="true">
        <tr class="listOdd">
          <td align="center" colspan="5">
            <bean:message key="cs.collaboration.noDiscussionMessages"/>
          </td>
        </tr>
      </logic:equal>

</table>


<!--end main content area here { list of messages } -->
    
<!--start top of message list, discussion index buttons area here--> 
<a name="#bottom"/>
<div class="globalButtonWrap">
  <input type="button" class="globalButton" value="<bean:message key="cs.message.top"/>" onclick="location='#top'"/>
  <input type="button" class="globalButton" value="<bean:message key="cs.discussions.index"/>" onclick="location='<html:rewrite page="/cs/discussionList.do" name="micrositeNaviInfoView" property="urlParams"/>'"/>
</div>

<!--end top of message list, discussion index buttons area here-->


<!--start create new message area here-->
<logic:notEqual name="isMSReadOnly" scope="request" value="true">
<a name="#create"></a>  
<br>
<%-- Add attachment code here --%>
<%-- form name="postForm" action="/cgi-bin/cp_upload.exe" 
      method="post" enctype="multipart/form-data" --%>
<html:form action="/cs/messageSave.do">

<bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>

<html:hidden property="returnId" value="-1"/>
<html:hidden property="sequenceKey"/>

<input type="hidden" name="parentContentType" value="25"/> <!-- message cnt type -->

</div>
    
    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:message key="cs.message.create.new.message"/>
      </span>
	  <span class="right">&nbsp;</span>
    </div> 
    <!--end title bar here-->      

<div class="blockWrap"> 

<table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="message table">    
  <!-- name -->
  <tr>
    <td nowrap width="20%" class="label"><bean:message key="cs.message.email"/>*:</td>
    <td width="80%" nowrap class="labelField"> 
      <html:text size="31" maxlength="80" readonly="true" property="email"/>
    </td>
  </tr>
  <tr>
    <td nowrap width="20%" class="label"><bean:message key="cs.message.subject"/>*:</td>
    <td width="80%" nowrap class="labelField"> 
      <html:text size="31" maxlength="80" property="title"/>
    </td>
  </tr>
  <tr>
    <td nowrap width="20%" class="label" valign="top"><bean:message key="cs.message.content"/>:</td>
    <td width="80%" nowrap class="labelField"> 
      <textarea cols="30" rows="5" name="body" wrap="virtual"><bean:write name="csMessageListEditForm" property="body"/></textarea>
    </td>
  </tr>
</table>
      
<% // Need to define the attachment form bean for the included JSP %>
   <!-- Start Display attachment. -->
    <script language="JavaScript">
      var nextPage = '<html:rewrite page="/cs/messageAttachmentAdd.do"/>';
      var attachmentDeleteAction = '<html:rewrite page="/cs/messageAttachmentDelete.do" />';

      <logic:equal name="csMessageListEditForm" property="numFiles" value="0">
        var nextActionAfterCancel= '/cs/discussionView.do';
      </logic:equal>
      <logic:notEqual name="csMessageListEditForm" property="numFiles" value="0">
        var nextActionAfterCancel= '/cs/messageCancel.do';
      </logic:notEqual>
  
      var nextActionAfterReset = '/cs/discussionView.do';
      
    </script>
    
    <bean:define id="formBeanUsed" name="csMessageListEditForm" toScope="request" />
    <%@ include file="/cs/microsite/attachment/attachmentEdit.jsp" %>
    <!-- end of attachments secion -->

  
<!--end main content area here-->

<!--start reset, cancel, save buttons bar area here-->
<div class="pageButtonWrap" align="right">
  <!-- reset button -->
  <html:reset styleClass="pageButton" property="resetBtn" titleKey="cs.message.clear"
              onclick='return resetAttachment(this.form)'>
    <bean:message key="cs.message.clear"/>
  </html:reset>
  <!-- save button -->
  <html:submit styleClass="pageButton" property="saveBtn" 
      titleKey="cs.message.post.new.message" onclick="return onClickPost(this.form)">
    <bean:message key="cs.message.post.new.message"/>
  </html:submit>
</div>
<!--end reset, cancel, save buttons bar area here-->

</html:form>
</logic:notEqual>

</div>

    </td>
  </tr>
</table>   

